define(['jquery','zTree'],function($,ztree){
	let _ztree = {};
	_ztree.setZtree = function(dom,url){
		 let setting = {
	        check: {
	            enable: true,
	            chkStyle: "radio",
	            radioType: 'all'
	        },
	        data: {
	            simpleData: {
	                enable: true
	            }
	        },
	        async: {
	            enable: true,
	            url:url,
	            autoParam:["id"],
	            type: "post",
	            dataFilter: filter
	        },
	        callback:{
	            onCheck:zTreeOnCheck
	        }
	    };

	    $.fn.zTree.init($(dom), setting);

	    function filter(treeId, parentNode, childNodes) {
	        let nodes = setNode(childNodes);
	        return nodes;
	    }
	}

	function setNode(data){
	    $.each(data,function(index, el) {
	        el.name = el.name;el.open = true;
	        if(el.children != ''){
	            setNode(el.children);
	            el.iconClose = "./js/lib/zTree/css/zTreeStyle/img/diy/1_close.png";
	            el.iconOpen = "./js/lib/zTree/css/zTreeStyle/img/diy/1_open.png";
	        }else{
	            el.icon = "./js/lib/zTree/css/zTreeStyle/img/diy/2.png";
	        }
	    });
	    return data;
	}
	function zTreeOnCheck(event, treeId, treeNode){
	    currentOrgId = treeNode.id;
	}

	return _ztree;
})